package concurrent.mysynchronized;

/**
 * @package concurrent.mysynchronized
 * @Class DisappearRequest1
 * @Description 消失的请求
 * @Author zhangxinhua
 * @Date 20-1-9 上午11:05
 */
public class DisappearRequest1 implements Runnable{
    static DisappearRequest1 instance = new DisappearRequest1();

    static int i=0;

    public static void main(String[] args) throws InterruptedException {
        for (int i1 = 0; i1 < 100; i1++) {
            i = 0;
            test();
        }
    }

    public static void test() throws InterruptedException {
        Thread t1 = new Thread(instance);
        Thread t2 = new Thread(instance);
        t1.start();
        t2.start();
        t1.join();
        t2.join();
        System.out.println(i);
    }
    @Override
    public void run() {
        synchronized (this) {
            for (int j = 0; j < 1000000; j++) {
                i++;
            }
        }
    }
}
